package 常见容器;

import java.util.Scanner;

public class 模拟队列 {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int[] arr = new int[100010];
        int hh = 0, tt = -1;

        int t = sc.nextInt();
        while (t-- > 0) {
            String s = sc.next();
            if("push".equals(s)) {
                int x = sc.nextInt();
                if(tt > 100010)tt = -1;//继续
                arr[++tt] = x;
            } else if("pop".equals(s)) {
                hh++;
            } else if("empty".equals(s)) {
                if(tt >= hh) {
                    System.out.println("NO");
                } else {
                    System.out.println("YES");
                }
            } else {
                System.out.println(arr[hh]);
            }
        }
    }
}
